package ${sourceBasePackage}.controller<#if sourceIncludeModule == 'Y'>.${moduleName}</#if>;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.idp.common.base.BaseController;
import com.idp.common.model.PageModel;
import com.idp.common.model.ResultModel;
import ${sourceBasePackage}.dto<#if sourceIncludeModule == 'Y'>.${moduleName}</#if>.${entityName}Dto;
import ${sourceBasePackage}.dto<#if sourceIncludeModule == 'Y'>.${moduleName}</#if>.${entityName}SearchDto;
import ${sourceBasePackage}.service<#if sourceIncludeModule == 'Y'>.${moduleName}</#if>.${entityName}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ${description}Controller
 * @author ${author}
 */
@Api(tags="${description}")
@RestController
@RequestMapping("/${entityName?uncap_first}/")
public class ${entityName}Controller extends BaseController {

	@Autowired
	private ${entityName}Service ${entityName?uncap_first}Service;

	/**
	 * 分页查询
	 * @param ${entityName?uncap_first}SearchDto
	 * @return
	 */
	@ApiOperation(value="分页查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "页数", paramType = "query", required = true, defaultValue = "1"),
		@ApiImplicitParam(name = "rows", value = "每页行数", paramType = "query", required = true, defaultValue = "10")
	})
	@PostMapping("findByPage")
	public ResultModel<PageModel<${entityName}Dto>> findByPage(@RequestBody ${entityName}SearchDto ${entityName?uncap_first}SearchDto) {
		return ResultModel.success(${entityName?uncap_first}Service.findByPage(${entityName?uncap_first}SearchDto));
	}

	/**
	 * 通过id查询
	 * @param ${entityName?uncap_first}Dto
	 * @return
	 */
	@ApiOperation(value="通过id查询")
	@ApiOperationSupport(includeParameters = {"${entityName?uncap_first}Dto.${pkPropertyName}"})
	@PostMapping("getById")
	public ResultModel<${entityName}Dto> getById(@RequestBody ${entityName}Dto ${entityName?uncap_first}Dto) {
		return ResultModel.success(${entityName?uncap_first}Service.getById(${entityName?uncap_first}Dto.get${pkPropertyName?cap_first}()));
	}

	/**
	 * 新增
	 * @param ${entityName?uncap_first}Dto
	 * @return
	 */
	@ApiOperation(value="新增")
	@ApiOperationSupport(ignoreParameters = {"${entityName?uncap_first}Dto.${pkPropertyName}"})
	@PostMapping("add")
	public ResultModel add(@RequestBody ${entityName}Dto ${entityName?uncap_first}Dto) {
		${entityName?uncap_first}Service.add(${entityName?uncap_first}Dto);
		return ResultModel.success("新增成功", null);
	}

	/**
	 * 修改
	 * @param ${entityName?uncap_first}Dto
	 * @return
	 */
	@ApiOperation(value="修改")
	@PostMapping("update")
	public ResultModel update(@RequestBody ${entityName}Dto ${entityName?uncap_first}Dto) {
		${entityName?uncap_first}Service.update(${entityName?uncap_first}Dto);
		return ResultModel.success("修改成功", null);
	}

	/**
	 * 删除
	 * @param ${entityName?uncap_first}Dto
	 * @return
	 */
	@ApiOperation(value="删除")
	@ApiOperationSupport(includeParameters = {"${entityName?uncap_first}Dto.${pkPropertyName}"})
	@PostMapping("delete")
	public ResultModel delete(@RequestBody ${entityName}Dto ${entityName?uncap_first}Dto) {
		${entityName?uncap_first}Service.delete(${entityName?uncap_first}Dto.get${pkPropertyName?cap_first}());
		return ResultModel.success("删除成功", null);
	}

}
